package com.whut.controller;


import com.whut.model.Project;
import com.whut.service.ProjectService;
import com.whut.v_vo.ProjectBuildVO;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/project")
public class ProjectController {

    private final ProjectService projectService;


    public ProjectController(ProjectService projectService) {
        this.projectService = projectService;
    }

    @GetMapping("/all")
    public List<Project> allProject() {
        return projectService.all();
    }

    @GetMapping("/{projectId}")
    public Project findProject(@PathVariable Integer projectId) {
        return projectService.findProjectById(projectId);
    }

    @PostMapping
    public Project saveProject(@RequestBody Project project) {
        return projectService.saveProject(project);
    }

    @PutMapping
    public Project putProject(@RequestBody Project project) {
        return projectService.modifyProject(project);
    }

    @GetMapping("/build/all/{projectId}")
    public List<ProjectBuildVO> allProjectBuild(@PathVariable Integer projectId) {
        return projectService.projectBuilds(projectId);
    }

    @PostMapping("build")
    public ProjectBuildVO saveProjectBuild(@RequestBody ProjectBuildVO request) {
        return projectService.saveProjectBuild(request);
    }

    @PutMapping("build")
    public ProjectBuildVO modifyProjectBuild(@RequestBody ProjectBuildVO request) {
        return projectService.modifyProjectBuild(request);
    }

    @DeleteMapping("build/{buildId}")
    public ProjectBuildVO deleteProjectBuildById(@PathVariable Integer buildId) {
        return projectService.deleteByProjectBuildId(buildId);
    }


}
